<?php

class ExceptionPlugin extends \Yaf\Plugin_Abstract
{
    public function preResponse(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response)
    {
        $exception = $response->getException();
        if ($exception instanceof Exception) {
            // 获取异常信息
            $message = $exception->getMessage();
            $file = $exception->getFile();
            $line = $exception->getLine();

            // 将异常信息记录到日志
            $logMessage = "Exception occurred: $message in $file on line $line";
            $this->logException($logMessage);
        }
    }

    private function logException($message)
    {
        // 记录到日志文件
        $logFile = '/path/to/your/log/exception.log';
        error_log($message . "\n", 3, $logFile);
    }
}